//
//  UITextField+TGPlaceholder.m
//  TongGuanLease
//
//  Created by Henghuitong on 2022/7/1.
//

#import "UITextField+TGPlaceholder.h"
#import <objc/message.h>
NSString * const placeholderColorName = @"placeholderColor";

@implementation UITextField (TGPlaceholder)
+ (void)load
{
    Method  setPlaceholder = class_getInstanceMethod(self, @selector(setPlaceholder:));
    Method  bs_setPlaceholder = class_getInstanceMethod(self, @selector(bs_setPlaceholder:));

    method_exchangeImplementations(setPlaceholder, bs_setPlaceholder);
}

- (void)setPlaceholderColor:(UIColor *)placeholderColor
{
    if(placeholderColor != nil)
    {
        objc_setAssociatedObject(self,(__bridge const void *)(placeholderColorName), placeholderColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

        UILabel *placeholderLabel = [self valueForKeyPath:@"placeholderLabel"];

        placeholderLabel.textColor = placeholderColor;
    }
 
}

- (UIColor *)placeholderColor
{
    return objc_getAssociatedObject(self, (__bridge const void *)(placeholderColorName));
}

- (void)bs_setPlaceholder:(NSString *)placeholder
{
    [self bs_setPlaceholder:placeholder];
    self.placeholderColor = self.placeholderColor;


}





@end
